package com.hmdp.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author LA
 * @Date 2024/8/12 16:08
 * @Description: 向SpringMVC注册自定义配置类
 * WebMvcConfigurer这个接口是由springmvc专门提供的一个用于自定义配置的接口，
 * 只要我们实现了这个接口，就可以去完成各项与springmvc相关的配置
 * （比如注册自定义converter以及注册为自定义拦截器等等等）
 */
@Slf4j
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;
    @Autowired
    private RefreshTokenInterceptor refreshTokenInterceptor;
    /**
     * 注册身份校验拦截器
     * @param registry
     * 默认会按照注册顺序来决定拦截器的执行顺序，也可以通过order属性来决定拦截器的执行顺序
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.warn("开始注册全局前置token刷新拦截器.............");
        registry.addInterceptor(refreshTokenInterceptor);

        log.warn("开始注册身份校验拦截器.............");
        registry.addInterceptor(authenticationInterceptor)
                .excludePathPatterns("/user/login","/user/code","/blog/hot","/shop-type/**","/voucher/**","/shop/**");
    }
}
